/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package test;

import com.dksoft.model.CalendarMethod;
import com.dksoft.view.MainFrame;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 *
 * @author Dickson
 */
public class MyClassLoader {

    private void mymethod(){
       String dbPath = CalendarMethod.getDBPath();
        if (CalendarMethod.isFileExist(dbPath) == false) {
            CalendarMethod.createDirectory(dbPath);
            String[] sourceFiles = {"Calendar.data.db", "Calendar.index.db", "Calendar.trace.db"};
            for (String source : sourceFiles) {
                try {
                    File destFile = new File(dbPath + source);
                    System.out.println(" dest file = " + dbPath + source);
                    InputStream in = MyClassLoader.class.getResourceAsStream("/log4j.properties");
                    OutputStream out = new FileOutputStream(destFile);

                    byte[] buf = new byte[1024];
                    int len;
                    while ((len = in.read(buf)) > 0) {
                        out.write(buf, 0, len);
                    }
                    in.close();
                    out.close();
                    System.out.println("File copied.");
                } catch (FileNotFoundException ex) {
                    System.out.println(ex.getMessage() + " in the specified directory.");
                    System.exit(0);
                } catch (IOException e) {
                    System.out.println(e.getMessage());
                }
            }
        }
    }
    
    public static void main(String[] args) {
//        String systemResource = ClassLoader.getSystemResource("pojo").toString();
//        System.out.println("systemResource = " + systemResource);
       MyClassLoader clas = new MyClassLoader();
       clas.mymethod();
        
    }
}
